<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<script type="text/javascript">
    function handleAddressForm(addrId) {
        if (addrId) {
            $.post("${pageContext.request.contextPath}/address/getAddressById", {aid: addrId}, function (result) {
                if (checkLogin(result)) {
                    if (result) {
                        $("#addressFormModal").modal();
                        $("#addrProvince").val(result.province);
                        $("#addrCity").val(result.city);
                        $("#addrArea").val(result.area);
                        $("#addrContent").val(result.street);
                        $("#addrReceiver").val(result.receiver);
                        $("#addrTel").val(result.telephone);
                        $("#addrId").val(result.aid);
                    }
                    else {
                        $("#msgTitle").html("操作失败");
                        $("#msgBody").html("未读到当前地址信息");
                        $("#msgModal").modal();
                    }
                }
            }, "json");
        }
        else {
            $("#addressFormModal").modal();
        }
    }

    function setDefault(addrId, e) {
        $.post("${pageContext.request.contextPath}/address/setDefaultAddress", {aid: addrId}, function (result) {
            if (checkLogin(result)) {
                if (result == "success") {
                    $(".isDefault").html("");
                    $(e.target).parent().siblings("[class='isDefault']").html("默认地址");
                }
                else {
                    $("#msgTitle").html("操作失败");
                    $("#msgBody").html("设置默认收货地址失败");
                    $("#msgModal").modal();
                }
            }
        });
    }
</script>

<div class="modal fade" id="addressFormModal" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">
            <form class="form-inline" id="addrForm" method="post"
                  action="${pageContext.request.contextPath}/address/handleAddress">
                <div class="modal-header">
                    <button class="close" type="button" data-dismiss="modal">×</button>
                    <h4 class="modal-title" id="myModalLabel">添加/修改收货地址</h4>
                </div>
                <div class="modal-body">

                    <input type="hidden" id="addrId" name="aid" value="0"/>

                    <div class="form-group">
                        <label for="addrProvince"> 省 </label>
                        <input class="form-control" name="province" id="addrProvince" placeholder="省"
                               required/>
                    </div>
                    <div class="form-group">
                        <label for="addrCity"> 市</label>
                        <input class="form-control" name="city" id="addrCity" placeholder="市" required/>
                    </div>
                    <div class="form-group">
                        <label for="addrArea"> 区 </label>
                        <input class="form-control" name="area" id="addrArea" placeholder="区" required/>
                    </div>
                    <div class="form-group">
                        <label for="addrContent"> 街道</label>
                        <input class="form-control" name="street" id="addrContent" placeholder="街道"
                               required/>
                    </div>
                    <div class="form-group">
                        <label for="addrReceiver"> 收件人 </label>
                        <input class="form-control" name="receiver" id="addrReceiver" placeholder="收件人"
                               required/>
                    </div>
                    <div class="form-group">
                        <label for="addrTel"> 联系电话</label>
                        <input class="form-control" name="telephone" id="addrTel" placeholder="联系电话"
                               required/>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-primary" type="submit">确定</button>
                    <button class="btn btn-default" type="button" data-dismiss="modal">关闭窗口</button>
                </div>
            </form>
        </div>
    </div>
</div>
